{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Proximity analysis\n",
    "\n",
    "Proximity analysis tools help you answer one of the most common questions posed in spatial analysis: What is near what?\n",
    "\n",
    "Proximity tools are available under the sub module `use_proximity` in the `features` module of the API. This section of the guide talks about using two tools from this module - create buffers and plan routes."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Proximity-analysis\" data-toc-modified-id=\"Proximity-analysis-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Proximity analysis</a></span><ul class=\"toc-item\"><li><span><a href=\"#Create-buffers\" data-toc-modified-id=\"Create-buffers-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Create buffers</a></span><ul class=\"toc-item\"><li><span><a href=\"#Buffer-a-fixed-distance\" data-toc-modified-id=\"Buffer-a-fixed-distance-1.1.1\"><span class=\"toc-item-num\">1.1.1&nbsp;&nbsp;</span>Buffer a fixed distance</a></span></li><li><span><a href=\"#Buffer-based-on-a-numerical-field\" data-toc-modified-id=\"Buffer-based-on-a-numerical-field-1.1.2\"><span class=\"toc-item-num\">1.1.2&nbsp;&nbsp;</span>Buffer based on a numerical field</a></span></li></ul></li></ul></li><li><span><a href=\"#Plan-routes\" data-toc-modified-id=\"Plan-routes-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Plan routes</a></span><ul class=\"toc-item\"><li><ul class=\"toc-item\"><li><span><a href=\"#Routing-options\" data-toc-modified-id=\"Routing-options-2.0.1\"><span class=\"toc-item-num\">2.0.1&nbsp;&nbsp;</span>Routing options</a></span></li></ul></li></ul></li></ul></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create buffers\n",
    "\n",
    "The Create Buffers tool creates areas around input point, line, or area features to a specified distance. Running this tool creates output polygon layers of a specified radius. This tool is often used with overlay analysis to answer questions such as: 'What falls within 5 mile radius of this school?' Refer [here](http://doc.arcgis.com/en/arcgis-online/use-maps/create-buffers.htm) for more details on this tool.\n",
    "\n",
    "In the examaple below, let us create buffers of 50 mile radius around major ports along the West Coast of the USA."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=e0dae2efe40a414a9700bee3a35c846b' target='_blank'>\n",
       "                        <img src='' width='200' height='133' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=e0dae2efe40a414a9700bee3a35c846b' target='_blank'><b>Ports along the US West Coast</b>\n",
       "                        </a>\n",
       "                        <br/>Locations of various ports along the West Coast of the United States.<br/><img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\" width=16 height=16>Feature Layer Collection by api_data_owner\n",
       "                        <br/>Last Modified: July 18, 2023\n",
       "                        <br/>0 comments, 47 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"Ports along the US West Coast\" type:Feature Layer Collection owner:api_data_owner>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# connect to GIS\n",
    "from arcgis.gis import GIS\n",
    "gis = GIS(profile=\"your_online_profile\")\n",
    "ports_item = gis.content.get(\"e0dae2efe40a414a9700bee3a35c846b\")\n",
    "ports_item"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's render these ports on a map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=></img>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "map1 = gis.map('USA')\n",
    "map1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "map1.center = [39, -98]\n",
    "map1.zoom = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "map1.content.add(ports_item)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Buffer a fixed distance\n",
    "Access `create_buffers` from `use_proximity` sub module"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "{\"cost\": 0.021}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=c2f9bbd12eeb4bf89385a29267448e28' target='_blank'>\n",
       "                        <img src='http://static.arcgis.com/images/desktopapp.png' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=c2f9bbd12eeb4bf89385a29267448e28' target='_blank'><b>Buffers_around_ports</b>\n",
       "                        </a>\n",
       "                        <br/><img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\" width=16 height=16>Feature Layer Collection by arcgis_python\n",
       "                        <br/>Last Modified: April 11, 2024\n",
       "                        <br/>0 comments, 0 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"Buffers_around_ports\" type:Feature Layer Collection owner:arcgis_python>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from arcgis.features import use_proximity\n",
    "\n",
    "#access the first layer in ports_item\n",
    "ports_layer1 = ports_item.layers[0]\n",
    "ports_buffer50 = use_proximity.create_buffers(ports_layer1, distances=[50], units = 'Miles', output_name='Buffers around ports')\n",
    "ports_buffer50"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A buffer of 50 miles around each of these ports has been created."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "arcgis.gis.Item"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(ports_buffer50)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`ports_buffer50` is a new Feature Collection Item in portal. If we didn't specify the `output_name` parameter while running the tool, `ports_buffer50` would instead be an in-memory Feature Collection object and would not be saved as an item in the portal.\n",
    "\n",
    "Let's add the result to a new map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=></img>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "map2 = gis.map('USA')\n",
    "map2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "map2.zoom = 2\n",
    "map2.center = [39, -98]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "map2.content.add(ports_buffer50.layers[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Buffer based on a numerical field\n",
    "Sometimes, it makes sense to vary the buffered distance by a field on the layer. For instance, when creating buffers around hazardous sites, you may want to vary the distance by the type or quantity of materials held in the facility.\n",
    "Such kinds of buffers can be created by specifying a numerical field to the `field` parameter. Let us query all the fields on this layer and determine which can be used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{\n",
       "   \"name\": \"country\",\n",
       "   \"type\": \"esriFieldTypeString\",\n",
       "   \"actualType\": \"nvarchar\",\n",
       "   \"alias\": \"country\",\n",
       "   \"sqlType\": \"sqlTypeNVarchar\",\n",
       "   \"length\": 4000,\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"globalid\",\n",
       "   \"type\": \"esriFieldTypeString\",\n",
       "   \"actualType\": \"nvarchar\",\n",
       "   \"alias\": \"globalid\",\n",
       "   \"sqlType\": \"sqlTypeNVarchar\",\n",
       "   \"length\": 4000,\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"harborsize\",\n",
       "   \"type\": \"esriFieldTypeString\",\n",
       "   \"actualType\": \"nvarchar\",\n",
       "   \"alias\": \"harborsize\",\n",
       "   \"sqlType\": \"sqlTypeNVarchar\",\n",
       "   \"length\": 4000,\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"label_position\",\n",
       "   \"type\": \"esriFieldTypeString\",\n",
       "   \"actualType\": \"nvarchar\",\n",
       "   \"alias\": \"label_position\",\n",
       "   \"sqlType\": \"sqlTypeNVarchar\",\n",
       "   \"length\": 4000,\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"latitude\",\n",
       "   \"type\": \"esriFieldTypeDouble\",\n",
       "   \"actualType\": \"float\",\n",
       "   \"alias\": \"latitude\",\n",
       "   \"sqlType\": \"sqlTypeFloat\",\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"longitude\",\n",
       "   \"type\": \"esriFieldTypeDouble\",\n",
       "   \"actualType\": \"float\",\n",
       "   \"alias\": \"longitude\",\n",
       "   \"sqlType\": \"sqlTypeFloat\",\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"port_name\",\n",
       "   \"type\": \"esriFieldTypeString\",\n",
       "   \"actualType\": \"nvarchar\",\n",
       "   \"alias\": \"port_name\",\n",
       "   \"sqlType\": \"sqlTypeNVarchar\",\n",
       "   \"length\": 4000,\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"short_form\",\n",
       "   \"type\": \"esriFieldTypeString\",\n",
       "   \"actualType\": \"nvarchar\",\n",
       "   \"alias\": \"short_form\",\n",
       "   \"sqlType\": \"sqlTypeNVarchar\",\n",
       "   \"length\": 4000,\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"geometry_x\",\n",
       "   \"type\": \"esriFieldTypeInteger\",\n",
       "   \"actualType\": \"int\",\n",
       "   \"alias\": \"geometry.x\",\n",
       "   \"sqlType\": \"sqlTypeInteger\",\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"geometry_y\",\n",
       "   \"type\": \"esriFieldTypeInteger\",\n",
       "   \"actualType\": \"int\",\n",
       "   \"alias\": \"geometry.y\",\n",
       "   \"sqlType\": \"sqlTypeInteger\",\n",
       "   \"nullable\": true,\n",
       "   \"editable\": true,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"ObjectId\",\n",
       "   \"type\": \"esriFieldTypeOID\",\n",
       "   \"actualType\": \"int\",\n",
       "   \"alias\": \"ObjectId\",\n",
       "   \"sqlType\": \"sqlTypeInteger\",\n",
       "   \"nullable\": false,\n",
       "   \"editable\": false,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": null\n",
       " },\n",
       " {\n",
       "   \"name\": \"GlobalID_2\",\n",
       "   \"type\": \"esriFieldTypeGlobalID\",\n",
       "   \"alias\": \"GlobalID_2\",\n",
       "   \"sqlType\": \"sqlTypeOther\",\n",
       "   \"length\": 38,\n",
       "   \"nullable\": false,\n",
       "   \"editable\": false,\n",
       "   \"domain\": null,\n",
       "   \"defaultValue\": \"NEWID() WITH VALUES\"\n",
       " }]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ports_layer1.properties.fields"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`latitude` seems to be a suitable field. We will now use this field while creating buffers."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "{\"cost\": 0.021}\n"
     ]
    }
   ],
   "source": [
    "ports_buffer_lat = use_proximity.create_buffers(ports_layer1,\n",
    "                                                field='latitude',\n",
    "                                                units='kilometers',\n",
    "                                                output_name='ports_buffers_with_lat')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div class=\"item_container\" style=\"height: auto; overflow: hidden; border: 1px solid #cfcfcf; border-radius: 2px; background: #f6fafa; line-height: 1.21429em; padding: 10px;\">\n",
       "                    <div class=\"item_left\" style=\"width: 210px; float: left;\">\n",
       "                       <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=856255fdd58342e5bd1e804880faf548' target='_blank'>\n",
       "                        <img src='http://static.arcgis.com/images/desktopapp.png' class=\"itemThumbnail\">\n",
       "                       </a>\n",
       "                    </div>\n",
       "\n",
       "                    <div class=\"item_right\"     style=\"float: none; width: auto; overflow: hidden;\">\n",
       "                        <a href='https://geosaurus.maps.arcgis.com/home/item.html?id=856255fdd58342e5bd1e804880faf548' target='_blank'><b>ports_buffers_with_lat</b>\n",
       "                        </a>\n",
       "                        <br/><img src='https://geosaurus.maps.arcgis.com/home/js/jsapi/esri/css/images/item_type_icons/featureshosted16.png' style=\"vertical-align:middle;\" width=16 height=16>Feature Layer Collection by arcgis_python\n",
       "                        <br/>Last Modified: April 11, 2024\n",
       "                        <br/>0 comments, 0 views\n",
       "                    </div>\n",
       "                </div>\n",
       "                "
      ],
      "text/plain": [
       "<Item title:\"ports_buffers_with_lat\" type:Feature Layer Collection owner:arcgis_python>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ports_buffer_lat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will add this result to the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=></img>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "map3 = gis.map('USA')\n",
    "map3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "map3.zoom = 2\n",
    "map3.center = [39, -98]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "map3.content.add(ports_buffer_lat.layers[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plan routes\n",
    "Plan Routes determines how a fleet of vehicles can visit a set of stops in the least amount of time. The plan routes tool is versatile and can be used to plan either a simple route direction or plan the travel of a fleet of vehicles. To learn more about this tool visit the [tool documentation](http://doc.arcgis.com/en/arcgis-online/use-maps/plan-routes.htm).\n",
    "\n",
    "In the example below, we will observe how to plan a simple route for tourists when they visit major attractions in Los Angeles. Our stops would be [Universal studios](https://en.wikipedia.org/wiki/Universal_Studios_Hollywood), [Griffith observatory](https://en.wikipedia.org/wiki/Griffith_Observatory), [Disneyland amusement park](https://en.wikipedia.org/wiki/Disneyland), [Hollywood walk of fame](https://en.wikipedia.org/wiki/Hollywood_Walk_of_Fame) and back to [Los Angeles international airport](https://en.wikipedia.org/wiki/Los_Angeles_International_Airport).\n",
    "\n",
    "At a minimum, the plan routes tool accepts a stop layer, start layer, route count, and the maximum number of stops per route."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# search for feature collections containing the attractions and destination.\n",
    "stops_item = gis.content.search(\"LA_tourism_stops\", \"Feature Collection\", max_items=1)[0]\n",
    "airport_item = gis.content.search(\"LAX_airport\", \"Feature Collection\", max_items=1)[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, let's add the attractions and destination to a map."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us extract the feature data from the items and assign them to two `FeatureCollection` variables to be used with the routes tool. The last layer in the item contains the actual features (within a [`FeatureSet`](/python/api-reference/arcgis.features.toc.html#featureset)) of the feature collection."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "stops_fc = stops_item.layers[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "airport_fc = airport_item.layers[3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's map the locations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map4 = gis.map(\"Los Angeles, California\")\n",
    "map4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "map4.center = [33.9422, -118.4036]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "map4.zoom = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [],
   "source": [
    "stops_fset = stops_fc.query()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "airport_fset = airport_fc.query()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "map4.content.draw(stops_fset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "from arcgis.map import symbols, renderers\n",
    "new_sym = symbols.SimpleMarkerSymbolEsriSMS(\n",
    "    color=[74,103,65,255],\n",
    "    style=symbols.SimpleMarkerSymbolStyle.esri_sms_diamond\n",
    ")\n",
    "pt_render = renderers.SimpleRenderer(\n",
    "    symbol=new_sym\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "map4.content.draw(\n",
    "    shape=airport_fset,\n",
    "    symbol = new_sym\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Routing options\n",
    "In the tool below, `route_count` is 1, since there is just one vehicle carrying the tourists and all tourists need to visit all attractions. In other use cases, when there are multiple vehicles at disposal and not everyone needs to stop at all stops, this parameter can be increased. The `max_stops_per_route` similarly reflects the maximum work load a vehicle can take in a multiple vehicle scenario. The `route_start_time` parameter can be used to plan routes in advance and account for traffic at that time."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Travel mode not set, using default travel mode\n",
      "Network elements with avoid-restrictions are traversed in the output (restriction attribute names: \"Through Traffic Prohibited\").\n",
      "{\"cost\": 1.0}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'routes_layer': <FeatureCollection>,\n",
       " 'assigned_stops_layer': <FeatureCollection>}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "route1 = use_proximity.plan_routes(stops_fc, route_count=1,\n",
    "                                   max_stops_per_route=5,\n",
    "                                   route_start_time = time.time(),\n",
    "                                   start_layer = airport_fc)\n",
    "route1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have successfully calculated the route- let's add it back to the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "map4.content.draw(route1[\"routes_layer\"].query())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": true,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
